<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- <style>
        .box{
            width: 800px;
            border: 1px solid #ccc;
            margin: 50px ;
            text-align: center;
        }
        p{
            text-align: center;
        }
        button{
            padding: 8px 16px;
            margin: 10px;
            
        }
    </style> -->
</head>
<body>
    <div id="box">
        <p>姓名</p>
        <button class="statbtn">开始</button>
        <button class="endbtn">结束</button>
    </div>
    <script>
        const names = ['张三','李四','王五','李白','杜甫']
        const statbtn = document.querySelector('.statbtn')
        const endbtn = document.querySelector('.endbtn')
        const p = document.querySelector('p')

        let timer = 0
        let ran = 0
        statbtn.addEventListener('click',function(){
            timer = setInterval(function(){
                const ran = Math.floor(Math.random() * names.length)
                p.innerHTML= names[ran]
            },100)
            
        })
        endbtn.addEventListener('click',function(){
            clearInterval(timer)
            names.splice(ran,1)
            console.log(names);
            
        })
    </script>
</body>
</html>